// 部门管理， 部门编辑表单
import { deepCopy } from '@/utils/tools' 


// 新建状态

function same (departments, errorInfo:string = '部门名称已存在, 请使用其他名称'){
    
    function validator (rule, value, callback,){
        for(let item of departments){
            let info:any = ''
            if(item.name === value){
                callback(new Error(errorInfo))

                return
            }
        }
        callback()
    }
    
    return { validator, trigger: 'blur' }
}

const newForm:formInf.parckCmp[] = [


    {
        label: '部门名称',
        component: 'input',
        conf: {},
        span: 16,
        key: 'name',
        same:same,
        ruleValidate:[
            {required:true, trigger:'blur' , message:'名称不能为空'}
        ]
    },
    {
        label:'部门类型',
        component: 'select',
        span: 8,
        key: 'kind',
        conf: {
            options: [
              
                {
                    label: '营业部',
                    value: '营业部'
                },
                {
                    label: '管理部门',
                    value: '管理部门'
                },
                {
                    label: '支持部',
                    value: '支持部'
                },
                {
                    label: '技术部',
                    value: '技术部'
                },
                {
                    label: '财务部',
                    value: '财务部'
                },
                {
                    label: '综合部门',
                    value: '综合部门'
                },
                {
                    label: '社区门店',
                    value: '社区门店'
                }

                
            ]
        },
        
    },
    {
        label: '部门级别',
        component: 'select',
        conf: {
            options: [

                {
                    label: '特级',
                    value: '特级'
                },
                {
                    lable: '一级',
                    value: '一级'
                },
                {
                    label: '二级',
                    value: '二级'
                },
                {
                    label: '三级',
                    value: '三级'
                },
                
            ]
        },
        span: 8,
        key:'level'
    },
    {
        label: '运营模式',
        component:'select',
        span: 8,
        key: 'businessModel',
        conf: {
            options: [

                {
                    label: '直营',
                    value: '直营'
                },
                {
                    label: '加盟',
                    value: '加盟'
                },
                {
                    label: '合作分利',
                    value: '合作分利'
                },
                {
                    label: '注资合作',
                    value: '注资合作' 
                },
                {
                    label: '行政设置',
                    value: '行政设置'
                }
                
            ]
        },
       
    },
    {
        label: '推荐人',
        component: 'input',
        conf: {},
        span: 8,
        key: 'refereedBy'
    },

    
];


// 编辑状态
const editForm = deepCopy(newForm);

editForm[0]['conf'] = {
    disabled: true,
}

// 只读状态
const readonly = deepCopy(newForm);

readonly.forEach(item =>{

    item = Object.assign(item, {

        component: 'input',
        conf: {
            readonly: true
        },
        
    })
    
})


export {

    newForm,
    editForm,
    readonly

};